﻿using Newtonsoft.Json;
using Ozone.BLL;
using Ozone.Device;
using ServiceStack.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.SystemCenter.AdvancedParameter
{
    /// <summary>
    /// RotaryEvaporatorAdvancedParameter.xaml 的交互逻辑    旋蒸仪器
    /// </summary>
    public partial class RotaryEvaporatorAdvancedParameter : UserControl
    {
        public RotaryEvaporatorAdvancedParameter()
        {
            InitializeComponent();
        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //LiftData liftData = new LiftData();
            //liftData.set = 0;

            //LiftRequest liftRequest = new LiftRequest();
            //liftRequest.lift = liftData;
            //string A = JsonConvert.SerializeObject(liftRequest);

            //ApiCaller apiCaller = new ApiCaller();
            //apiCaller.CallBUCHIApi(A);
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {

        }
        public class ApiCaller
        {
            /// <summary>
            /// 调用旋蒸仪器API接口
            /// </summary>
            /// <param name="jsonContent"></param>
            /// <returns></returns>
            public async Task<bool> CallBUCHIApi(string jsonContent)
            {
                bool ExecState = false;
                try
                {
                    // 设置证书验证回调（注意：在生产环境中，不建议总是返回 true，这会使 HTTPS 安全性失效）
                    var handler = new HttpClientHandler
                    {
                        ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
                    };

                    using (var client = new HttpClient(handler))
                    {
                        client.BaseAddress = new Uri("https://192.168.0.163/"); // 可选：设置基地址（如果所有请求都发往同一个基地址）
                        var request = new HttpRequestMessage(HttpMethod.Put, "/api/v1/process")
                        {
                            Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
                        };
                        request.Headers.Add("Authorization", "Basic cnc6NExuMUJLZkE=");

                        HttpResponseMessage response = await client.SendAsync(request);
                        response.EnsureSuccessStatusCode(); // 如果响应状态码表示错误，则抛出异常

                        string responseBody = await response.Content.ReadAsStringAsync();
                        if (!string.IsNullOrEmpty(responseBody))
                        {
                            ExecState = true; // 根据实际业务逻辑，这里可能需要根据 responseBody 的内容来决定 ExecState 的值
                        }
                    }
                }
                catch (HttpRequestException e)
                {
                    // 记录异常或执行其他错误处理逻辑
                    // ExecState 已经被设置为 false，不需要再次赋值
                }

                return ExecState;
            }
        }
        //升降  高度范围0-204
        #region

        public class LiftRequest
        {
            public LiftData lift { get; set; }
        }

        public class LiftData
        {
            //升降高度
            [Required]
            [Range(0, 204)]
            public int set { get; set; }
        }
        #endregion
        /// <summary>
        /// 打开电磁阀
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_OpenSolenoidValve(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 关闭电磁阀
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_CloseSolenoidValve(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 上升旋蒸仪
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_RiseRotary(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 下降旋蒸仪
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDownRotary(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 旋转旋蒸仪
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRotateRotary(object sender, RoutedEventArgs e)
        {
            try
            {
               
            }
            catch
            {

            }
        }
        /// <summary>
        /// 旋蒸加热
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHeating(object sender, RoutedEventArgs e)
        {
            try
            {
              
            }
            catch
            {

            }
        }
        /// <summary>
        /// 旋蒸仪真空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVacuumRotary(object sender, RoutedEventArgs e)
        {
            try
            {

            }
            catch
            {

            }
        }

        /// <summary>
        /// 设置流速
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_ZSBLSClick(object sender, RoutedEventArgs e)
        {
            double Flow = Convert.ToDouble(txt_StockBottlesuduliusu.Text);

        }

        private void Button_ZSBKClick(object sender, RoutedEventArgs e)
        {
        }

        private void Button_ZSBGClick(object sender, RoutedEventArgs e)
        {
        }

        /// <summary>
        /// 真空机开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVacuumRotaryopen(object sender, RoutedEventArgs e)
        {
        }

        /// <summary>
        /// 真空机器关
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVacuumRotaryClose(object sender, RoutedEventArgs e)
        {
        }
    }
}
